package com.cn.yang.servlet.mainPage;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.model.aboutUs.AboutUsModel;
import com.cn.yang.model.mainPage.MainPageModel;
import com.cn.yang.service.AboutUsService;
import com.cn.yang.service.MainPageService;
import com.cn.yang.service.impl.AboutUsServiceImpl;
import com.cn.yang.service.impl.MainPageServiceImpl;
import com.cn.yang.util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/mainPage/findMainPage")
public class FindMainPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        MainPageService service = new MainPageServiceImpl();
        PageUtil pageUtil = new PageUtil();
        Integer pageSize = Integer.valueOf(req.getParameter("pageSize"));
        Integer pageNumber = Integer.valueOf(req.getParameter("pageNumber"));
        pageUtil.setPageNumber(pageNumber);
        pageUtil.setPageSize(pageSize);
        MainPageModel model = new MainPageModel();
        model.setPageUtil(pageUtil);
        List<MainPageModel> list = service.findMainPage(model);
        int count = service.countMainPage();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
